package com.grow.greenhouse.controller;


import com.grow.greenhouse.common.BaseResponse;
import com.grow.greenhouse.common.ErrorCode;
import com.grow.greenhouse.domain.Shed;
import com.grow.greenhouse.domain.request.ShedNameRequest;
import com.grow.greenhouse.exception.BusinessException;
import com.grow.greenhouse.service.ShedService;
import com.grow.greenhouse.utils.ResultUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/shed")
public class ShedController {

    @Resource
    private ShedService shedService;


    @ApiOperation("获取用户拥有的大棚")
    @GetMapping("/getshed")
    public BaseResponse<List<Shed>> getUserShed(HttpServletRequest request){
        List<Shed> shedList = shedService.getUserShed(request);
        return ResultUtils.success(shedList);
    }

    @ApiOperation("添加大棚")
    @PostMapping("/add")
    public BaseResponse<String> addUserShed(@RequestBody ShedNameRequest shedNameRequest,
                                            HttpServletRequest request){
        if(shedNameRequest == null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"棚名称不能为空");
        }
        String add = shedService.addShed(shedNameRequest,request);
        return ResultUtils.success(add);
    }





}
